package com.example.ffepeg.ffe;

import java.io.IOException;

public class ffmpegAd {
    public static void main(String[] args) {
        // 输入的视频文件路径
        String videoInputPath = "src/main/resources/file/videoThen/hkahdfasdfasdfasd.mp4";
        // 输入的音频文件路径
        String audioInputPath = "src/main/resources/file/videoThen/holahsdlfjlasdjfads.mp3";
        // 输出的带有音频的视频文件路径
        String outputPath = "src/main/resources/out/output_video.mp4";

        // 构建FFmpeg命令
        String ffmpegCommand = "ffmpeg -stream_loop -1 -i \"" + audioInputPath + "\" -i \"" + videoInputPath +
                "\" -c:v copy -c:a aac -map 0:a -map 1:v -shortest \"" + outputPath + "\"";

        try {
            // 使用 ProcessBuilder 来启动一个新的进程，指定使用cmd.exe
            ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/c", ffmpegCommand);
          //  pb.inheritIO(); // 继承主程序的标准输入输出流
            Process process = pb.start();
            // 等待命令执行完成
            int exitCode = process.waitFor();
            System.out.println("FFmpeg command executed with exit code: " + exitCode);
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}
